"""
Given a string s, find the length of the longest substring without repeating characters.

给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度
"""
class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        遍历字符串，每次遍历都检查一次右指针的元素是否在其前面的子串中，
        若存在，则左指针不断向后移动直到右指针所指元素不在子串中
        """
        left, right = 0, 0
        maxLength = 0
        while right < len(s):
            while s[right] in s[left:right]:
                left += 1
            if right-left + 1>maxLength:
                maxLength = right - left + 1
            if s[right] not in s[left : right]:
                right += 1
        return maxLength